package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.TimeConstant;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.OtherIncomeSheetTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.OtherIncomeEnum;
import com.xbongbong.saas.enums.dictionary.PayMethodEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum TempOtherIncomeEnum {
    //刷脚本专用枚举
    BASE_INFO(OtherIncomeEnum.BASE_INFO),
    SHEET_TYPE_OTHER(OtherIncomeEnum.SHEET_TYPE_OTHER),
    SHEET_NO(OtherIncomeEnum.SHEET_NO),
    AMOUNT(OtherIncomeEnum.AMOUNT),
    INVOICE_AMOUNT(OtherIncomeEnum.INVOICE_AMOUNT),
    BELONG_ID(OtherIncomeEnum.BELONG_ID),
    INCOME_TIME(OtherIncomeEnum.INCOME_TIME),
    FUND_ACCOUNT(OtherIncomeEnum.FUND_ACCOUNT),
    PAY_METHOD(OtherIncomeEnum.PAY_METHOD),
    SYSTEM_INFO(OtherIncomeEnum.SYSTEM_INFO),
    MEMO(OtherIncomeEnum.MEMO),
    FILE(OtherIncomeEnum.FILE),
    ORIGIN_ID(OtherIncomeEnum.ORIGIN_ID),
    CREATOR_ID(OtherIncomeEnum.CREATOR_ID),
    ADD_TIME(OtherIncomeEnum.ADD_TIME),
    UPDATE_TIME(OtherIncomeEnum.UPDATE_TIME),

    ORIGIN_ID_LINK_TEXT(OtherIncomeEnum.ORIGIN_ID_LINK_TEXT),
    ;
    private OtherIncomeEnum anEnum;

    TempOtherIncomeEnum(OtherIncomeEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempOtherIncomeEnum> getAllEnum() {
        List<TempOtherIncomeEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initSheetTypeOther(FieldAttrEntity fieldAttrEntity){
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(OtherIncomeSheetTypeEnum.class, fieldAttrEntity.getFieldType());
        for (ItemPoJo itemPoJo : itemPoJoList) {
            itemPoJo.setNoEdit(BasicConstant.ONE);
            itemPoJo.setNoMove(BasicConstant.ONE);
        }
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.OTHER_INCOME.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.OTHER_INCOME.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.OTHER_INCOME_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        //不允许修改默认值
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
    }

    public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setIsOpen(0);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
    }

    public static void initBelongId(FieldAttrEntity fieldAttrEntity) {
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue("0");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initIncomeTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType( DateTimeEnum.TIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        defaultAttrPoJo.setDefaultValue("");
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setPeriodLimitType(true);
        saasParticularAttributePoJo.setDay(TimeConstant.MONTH);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    public static void initFundAccount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
        fieldAttrEntity.setMemo("账户信息可在【管理中心-其他设置-资金账户】中自定义修改");
    }

    public static void initPayMethod(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PayMethodEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    public static void initOriginId(FieldAttrEntity fieldAttrEntity) {
        //改为其他收入单类型，因为打开关联原始其他收入单详情的时候，是要用其他收入单的type去得到tab、button等（通过data内的付款单类型来区分具体哪种类型的其他收入单）
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.OTHER_INCOME.getCode());
        fieldAttrEntity.setLinkedText(ORIGIN_ID_LINK_TEXT.getAnEnum().getAttr());
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.OTHER_INCOME.getCode());
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
